/*
 * PanelHerramienta.java
 *
 * Created on 9 de noviembre de 2003, 11:24 PM
 */

package taladro.vista.proyecto;

import javax.swing.JDialog;
import taladro.AppTaladro;

/**
 *
 * @author  Javier
 */
public class PanelHerramienta extends javax.swing.JPanel {
    
    /** Creates new form PanelHerramienta */
    public PanelHerramienta() {
        initComponents();
    }
    
    public JDialog dialog;
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        lblHerramienta = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtLargo = new javax.swing.JTextField();
        btnContinuar = new javax.swing.JButton();
        lblAltura = new javax.swing.JLabel();
        txtAlto = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        txtPerforacion = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        btnTestAlto = new javax.swing.JButton();
        btnTestPerf = new javax.swing.JButton();

        setLayout(new java.awt.GridBagLayout());

        jLabel1.setFont(new java.awt.Font("Dialog", 1, 14));
        jLabel1.setText("Cambio de Herramienta");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
        add(jLabel1, gridBagConstraints);

        jLabel2.setText("Herramienta:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 2, 0, 0);
        add(jLabel2, gridBagConstraints);

        lblHerramienta.setText("T100021");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0);
        add(lblHerramienta, gridBagConstraints);

        jLabel3.setText("Tama\u00f1o:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(10, 2, 4, 0);
        add(jLabel3, gridBagConstraints);

        txtLargo.setText("5");
        txtLargo.setPreferredSize(new java.awt.Dimension(12, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 3, 2);
        add(txtLargo, gridBagConstraints);

        btnContinuar.setText("Continuar");
        btnContinuar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Continuar(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.gridwidth = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(12, 2, 7, 2);
        add(btnContinuar, gridBagConstraints);

        lblAltura.setText("Alto Columna");
        lblAltura.setToolTipText("Espacio entre la tablilla y la punta del taladro (sin herramienta)");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        add(lblAltura, gridBagConstraints);

        txtAlto.setText("30");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 3, 0);
        add(txtAlto, gridBagConstraints);

        jLabel4.setText("mm");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        add(jLabel4, gridBagConstraints);

        jLabel5.setText("mm");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        add(jLabel5, gridBagConstraints);

        jLabel6.setText("Perforaci\u00f3n");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 4;
        add(jLabel6, gridBagConstraints);

        txtPerforacion.setText("0.4");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(0, 10, 3, 0);
        add(txtPerforacion, gridBagConstraints);

        jLabel7.setText("mm");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 4;
        add(jLabel7, gridBagConstraints);

        btnTestAlto.setText("Probar");
        btnTestAlto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                testAlto(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        add(btnTestAlto, gridBagConstraints);

        btnTestPerf.setText("Probar");
        btnTestPerf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                testPerforar(evt);
            }
        });

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        add(btnTestPerf, gridBagConstraints);

    }// </editor-fold>//GEN-END:initComponents
    
    private void testPerforar(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_testPerforar
        try{
            double alto =  Double.parseDouble(this.txtAlto.getText());
            double largoHerr =  Double.parseDouble(this.txtLargo.getText());
            double perforacion =  Double.parseDouble(this.txtPerforacion.getText());
            AppTaladro.getApp().getProyecto().getMaquina().getColumna().mover(alto - largoHerr+ perforacion);
        }catch(Exception e){
            this.txtAlto.selectAll();
        }
    }//GEN-LAST:event_testPerforar
    
    private void testAlto(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_testAlto
        try{
            double alto =  Double.parseDouble(this.txtAlto.getText());
            double largoHerr =  Double.parseDouble(this.txtLargo.getText());
            AppTaladro.getApp().getProyecto().getMaquina().getColumna().mover(alto - largoHerr);
        }catch(Exception e){
            this.txtAlto.selectAll();
        }
    }//GEN-LAST:event_testAlto
    
    private void Continuar(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Continuar
        //this.setVisible(false);
        //((JDialog) this.getParent()).se
        //this.getParent().setVisible(false);
        //dialog = (JDialog) this.getParent();
        try{
            AppTaladro.getApp().getProyecto().getMaquina().getColumna().setLargoEjeZ(Double.parseDouble(this.txtAlto.getText()));
            AppTaladro.getApp().getProyecto().getMaquina().getColumna().setPosFresar(Double.parseDouble(this.txtPerforacion.getText()));
            dialog.dispose();
        }catch(Exception e){
            this.txtAlto.selectAll();
        }
        
    }//GEN-LAST:event_Continuar
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnContinuar;
    private javax.swing.JButton btnTestAlto;
    private javax.swing.JButton btnTestPerf;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel lblAltura;
    private javax.swing.JLabel lblHerramienta;
    private javax.swing.JTextField txtAlto;
    private javax.swing.JTextField txtLargo;
    private javax.swing.JTextField txtPerforacion;
    // End of variables declaration//GEN-END:variables
    
    
    public double getAltoHerramienta(){
        try{
            return Double.parseDouble( txtLargo.getText() );
        }catch( Exception e){
            return 50;
        }
    }
    
    public void setNombreHerramienta( String nombre ){
        lblHerramienta.setText(nombre);
    }
}
